package com.huawei.appgallery.forum.forum.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.animation.Interpolator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import o.bqx;
import o.bun.i;
import o.cjy;
import o.cjy.d;
import o.MinimumFactory;

@SuppressLint({"ClickableViewAccessibility"})
public class BounceHorizontalRecyclerView extends RecyclerView implements d {
    protected cjy ˏˏ = null;
    protected boolean ͺॱ = false;
    private boolean ـ = false;
    private float ॱʻ = 0.0f;
    private float ॱʼ = 0.0f;
    private boolean ॱʽ = false;
    private Interpolator ॱͺ;
    private boolean ᐝˋ = false;
    private b ᐝᐝ;
    private boolean ᐧ = false;
    private int ᐨ;

    public interface b {
        boolean ॱ();
    }

    public BounceHorizontalRecyclerView(Context context) {
        super(context);
        ˎ(null);
        ˏˎ();
    }

    public BounceHorizontalRecyclerView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        ˎ(attributeSet);
        ˏˎ();
    }

    public BounceHorizontalRecyclerView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        ˎ(attributeSet);
        ˏˎ();
    }

    private void ˏˎ() {
        this.ॱͺ = new d(null);
    }

    public void ˊ(int i, int i2) {
        super.ˊ(i, i2, this.ॱͺ);
    }

    private void ˎ(AttributeSet attributeSet) {
        if (attributeSet != null) {
            TypedArray typedArray = null;
            try {
                typedArray = getContext().obtainStyledAttributes(attributeSet, i.ᐝʼ);
                this.ͺॱ = typedArray.getBoolean(i.ॱﾟ, false);
                if (typedArray != null) {
                    typedArray.recycle();
                }
            } catch (Throwable e) {
                bqx.ˊ("BounceHorizontalRecyclerView", "init(AttributeSet attrs) ", e);
                if (typedArray != null) {
                    typedArray.recycle();
                }
            } catch (Throwable th) {
                if (typedArray != null) {
                    typedArray.recycle();
                }
            }
        }
        if (this.ͺॱ) {
            this.ˏˏ = new cjy((RecyclerView) this);
        }
    }

    public boolean dispatchTouchEvent(MotionEvent motionEvent) {
        switch (motionEvent.getAction()) {
            case 0:
                this.ॱʼ = motionEvent.getY();
                this.ॱʻ = motionEvent.getX();
                this.ᐧ = true;
                break;
            case 2:
                if (!this.ـ || !ˎ(motionEvent)) {
                    if (ॱ(motionEvent) < ˏ(motionEvent)) {
                        this.ॱʽ = false;
                        if (getParent() != null) {
                            getParent().requestDisallowInterceptTouchEvent(false);
                            break;
                        }
                    }
                    if (getParent() != null) {
                        getParent().requestDisallowInterceptTouchEvent(true);
                    }
                    this.ॱʽ = true;
                    return super.dispatchTouchEvent(motionEvent);
                }
                this.ॱʼ = motionEvent.getY();
                this.ॱʻ = motionEvent.getX();
                this.ॱʽ = false;
                if (getParent() != null) {
                    getParent().requestDisallowInterceptTouchEvent(false);
                }
                return super.dispatchTouchEvent(motionEvent);
                break;
        }
        return super.dispatchTouchEvent(motionEvent);
    }

    private boolean ˎ(MotionEvent motionEvent) {
        return (MinimumFactory.getBoolValue(getContext()) && motionEvent.getX() - this.ॱʻ > 0.0f && ˌ()) || (!MinimumFactory.getBoolValue(getContext()) && motionEvent.getX() - this.ॱʻ < 0.0f && ˋˋ());
    }

    public int ˏ(MotionEvent motionEvent) {
        return Math.abs((int) (motionEvent.getY() - this.ॱʼ));
    }

    public int ॱ(MotionEvent motionEvent) {
        return Math.abs((int) (motionEvent.getX() - this.ॱʻ));
    }

    public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
        if (this.ॱʽ && getParent() != null) {
            getParent().requestDisallowInterceptTouchEvent(true);
        }
        if (this.ͺॱ && this.ˏˏ != null) {
            this.ˏˏ.ˋ(motionEvent);
        }
        try {
            return super.onInterceptTouchEvent(motionEvent);
        } catch (IllegalArgumentException e) {
            return false;
        }
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (this.ॱʽ && getParent() != null) {
            getParent().requestDisallowInterceptTouchEvent(true);
        }
        try {
            if (this.ͺॱ && this.ˏˏ != null && this.ˏˏ.ˏ(motionEvent)) {
                return true;
            }
            return super.onTouchEvent(motionEvent);
        } catch (Throwable e) {
            bqx.ˊ("BounceHorizontalRecyclerView", "onTouchEvent(MotionEvent ev)  ", e);
            return false;
        }
    }

    public boolean ˌ() {
        return !canScrollHorizontally(-1);
    }

    public boolean ˋˋ() {
        return !canScrollHorizontally(1);
    }

    public boolean ˎˎ() {
        return false;
    }

    public boolean ˋᐝ() {
        return false;
    }

    public void ʼ(int i) {
        int ˌ = ʻ().ˌ();
        if (ʻ() instanceof LinearLayoutManager) {
            this.ᐨ = ((LinearLayoutManager) ʻ()).ʻॱ();
        }
        if (this.ᐧ && !this.ᐝˋ && this.ᐨ >= ˌ - 1 && this.ᐝᐝ != null) {
            this.ᐧ = false;
            if (this.ᐝᐝ.ॱ()) {
                this.ᐝˋ = true;
            }
        }
    }

    public void setOnLoadListener(b bVar) {
        this.ᐝᐝ = bVar;
    }

    public void setLoading(boolean z) {
        this.ᐝˋ = z;
    }

    public void setUnInterceptOnRight(boolean z) {
        this.ـ = z;
    }
}
